package com.woniuxy.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;

public class MyAspectJ {
    //前置通知
    public void myBefore(JoinPoint joinPoint){
        System.out.println("前置通知：模拟判断是否有@Transcational注解……");
        System.out.print("目标类："+joinPoint.getTarget().getClass().getName());
        System.out.println(",被织入的增强目标的方法是："+joinPoint.getSignature().getName());
    }
    //后置通知
    public void myAfterReturning(JoinPoint joinPoint){
        System.out.println("后置通知：模拟事务的提交……");
        System.out.print("目标类是："+joinPoint.getTarget());
        System.out.println("，被织入的增强目标的方法是："+joinPoint.getSignature().getName());
    }
    //环绕通知：不推荐使用
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕开始：执行目标方法之前……");
        Object proceed = proceedingJoinPoint.proceed();
        System.out.println("环绕结束：执行目标方法之后……");
        return proceed;
    }
    //异常通知
    public void myAfterThrowing(JoinPoint joinPoint,Throwable e){
        System.out.println("异常通知");
        System.out.println("报错信息"+e.getMessage());
    }
    //最终通知
    public void myAfter(){
        System.out.println("最终通知：模拟方法结束后释放资源，关闭SqlSession……");
    }
}
